import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: "/home",
    name: "Home",
    component: () => import('../views/home.vue')
  },
  {
    path: "/diet",
    // name: "Diet",
    component: () => import('../views/diet.vue'),
    children:[
      {
        path:"/",
      redirect: "dietCon"
      },
      {
        path: "dietCon",
        name: "DietCon",
        component: () => import('../components/dietCon.vue')
      }
    ]
  },
  {
    path: "/market",
    name: "Market",
    component: () => import('../views/market.vue')
  },
  {
    path: "/recuperate",
    name: "Recuperate",
    component: () => import('../views/recuperate.vue')
  },
  {
    path: "/mine",
    name: "Mine",
    component: () => import('../views/mine.vue')
  },
  {
    path: "/ceshiFu",
    name: "CeshiFu",
    component: () => import('../views/测试/ceshiFu.vue')
  },
  {
    path: "/ceshiZia",
    name: "CeshiZia",
    component: () => import('../views/测试/ceshiZia.vue')
    // ,
    // 路由独享守卫
    // beforeEnter(to,from,next){
    //   console.log(to)
    //   console.log(from)
    //   // 进行一些是否登录的判断判断成功让她进入  不成功不能进
    // //  alert("当前页面是vip页面,请登录")
    //   // next("/login")//不让下一步
    //   // next("/ceshiZia")
    // }
  },
  {
    path: "/ceshiZib",
    name: "CeshiZib",
    component: () => import('../views/测试/ceshiZib.vue')
    
  },
  {
    path: "/dietDetails",
    name: "DietDetails",
    component: () => import('../views/dietDetails.vue')
  },
  {
    path: "/marketDetails/:xiaoming",
    name: "MarketDetails",
    component: () => import('../views/marketDetails.vue')
  },
  {
    path: "/recupDetails",
    name: "RecupDetails",
    component: () => import('../views/recupDetails.vue')
  },
  {
    path: "/register",
    name: "Register",
    component: () => import('../views/register.vue')
  },
  {
    path: "/login",
    name: "Login",
    component: () => import('../views/login.vue')
  },
  {
    path: "/shopcart",
    name: "Shopcart",
    component: () => import('../views/shopcart.vue')
  },
  {
    path: "/vant",
    name: "Vant",
    component: () => import('../components/vant.vue')
  },
  {
    path: "/homeDetails",
    // name: "HomeDetails",
    component: () => import('../views/homeDetails.vue'),
    children:[
      {
        path:"/",
      redirect: "homeListOne"
      },
      {
        path: "homeListOne",
        name: "HomeListOne",
        component: () => import('../views/homeListOne.vue')
      },
      {
        path: "homeListTwo",
        name: "HomeListTwo",
        component: () => import('../views/homeListTwo.vue')
      },
    ]
  },
  
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "*",
    name: "/NotFound",
    component: () => import('../views/notFound.vue')
  }
]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// 以下代码解决如后报错
// Redirected when going from "/mine" to "/shopcart" via a navigation guard.
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}


// 全局前置守卫
// router.beforeEach((to,from,next)=>{
  // console.log("to",to);
  // console.log("from",from);
  // console.log("next",next);
  // if(to.path=="/shopcart"){
  //   alert("您还没有登录请登录后再试")
  //   next("/login")
    
  // }else{
  //   next()
  // }
// })
// 全局后置守卫
router.afterEach((to,from)=>{
  console.log("to",to);
  console.log("from",from);
})


export default router
